package com.nhjf.service.impl.system;

import java.io.Serializable;
import java.text.SimpleDateFormat;
import java.util.List;

import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.nhjf.command.system.CreateResourceCommand;
import com.nhjf.command.system.ModifyResourceCommand;
import com.nhjf.dao.system.ResourceDao;
import com.nhjf.model.system.Resource;
import com.nhjf.pojo.dto.result.ServiceResultDto;
import com.nhjf.pojo.qo.system.ResourceQo;
import com.nhjf.service.impl.BaseServiceImpl;
import com.nhjf.service.system.ResourceService;

@Transactional
@Service("resourceService")
public class ResourceServiceImpl extends BaseServiceImpl<Resource, ResourceQo, ResourceDao> implements ResourceService {

	@Autowired
	private ResourceDao resourceDao;
	@Override
	protected ResourceDao getDao() {
		// TODO Auto-generated method stub
		return resourceDao;
	}
	@Override
	public ServiceResultDto createResource(CreateResourceCommand createResourceCommand) {
		// TODO Auto-generated method stub
		ServiceResultDto resultDto = new ServiceResultDto();
		if(createResourceCommand==null) {
			resultDto.setSuccess(false);
			return resultDto;
		}
		if(createResourceCommand.getName()==null||createResourceCommand.getName().equals("")) {
			resultDto.setSuccess(false);
			return resultDto;
		}
		Resource re=new Resource();
		re.createResource(createResourceCommand);
		resourceDao.save(re);
		resultDto.setSuccess(true);
		return resultDto;
	}
	@Override
	public ServiceResultDto modifyResource(ModifyResourceCommand modifyResourceCommand) {
		// TODO Auto-generated method stub
		ServiceResultDto resultDto = new ServiceResultDto();
		
		Resource re=resourceDao.get(modifyResourceCommand.getResourceId());
		
		re.modifyResource(modifyResourceCommand);
		resourceDao.update(re);
		resultDto.setSuccess(true);
		return resultDto;
	}

}
